<?php
/**
 * O library self-testing file
 *
 * @author chedim
 */
class O_root_classes extends aSelfTest
{
    private $magic = 1;

    public function __construct()
    {
        $this->magic = time();
    }

    public function test_array_comparison() {
        $a1 = array(1,2,3);
        $a2 = array(1,2,3);
        $b1 = array(5,2,3,4);
        $this->check_true($a1 == $a2);
        $this->check_false($a1 == $b1);
        $this->check_true($a1 < $b1);
    }

    public function test_String_Slicing()
    {
        $string = new oString("fobar");
        $this->check_equals($string(0), "fobar");
        $this->check_equals($string(-4, 2), "ob");
        $this->check_equals($string(1, 2), "ob");
    }

    public function test_File_Writing()
    {
        $file = new oFile('.oFile-test-writing');
        $this->check_false($file->opened());
        $this->check_true($file->open("w"));
        $this->check_true($file->write($this->magic));
        $this->check_true($file->close());
    }

    public function test_File_Exists()
    {
        $file = new oFile('.oFile-test-writing');
        $this->check_true($file->exists());
    }

    public function test_File_Reading()
    {
        $file = new oFile('.oFile-test-writing');
        $this->check_false($file->opened());
        $this->check_true($file->open("r"));
        $this->check_equals($file->ReadAll(), $this->magic);
        $this->check_true($file->close());
    }

    public function test_File_Deleting() {
        $file = new oFile('.oFile-test-writing');
        $this->check_true($file->unlink());
    }

    public function test_Fsm_Cicle() {
        $state = new oFsmStatePrinter();
        $fsm = new oFsm($state);
        $fsm->ReadString(new oString('fsm test'));
    }
}
?>
